// pages/demo/demo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
    data2: [0, 1, 2, 3, 4, 5, 6],
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: false,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    swiperHeight: 940,
    topType: false,
    current: 0
  },

  onPageScroll(e) {
    if (e.scrollTop >= 40) {
      this.setData({
        topType: true
      })
    } else {
      this.setData({
        topType: false
      })
    }
  },
  onReachBottom() {
    if (this.data.current == 0) {
      this.data.data1.push(this.data.data1.length)
      this.setData({
        data1: [...this.data.data1]
      }, () => {
        this.getHeight(this.data.current)
      })
    } else {
      this.data.data2.push(this.data.data2.length)
      this.setData({
        data2: this.data.data2
      }, () => {
        this.getHeight(this.data.current)
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onReady: function (options) {
    this.getHeight(0)
  },
  getHeight(index) {
    const name = '.swiper-item' + index
    console.log(name)
    let query = wx.createSelectorQuery().in(this);
    query.select(name).boundingClientRect(data => {
      console.log(data.height)
      this.setData({
        swiperHeight: data.height
      })
    }).exec()
  },
  bindchange(e) {
    this.setData({
      current: e.detail.current
    }, () => {
      this.getHeight(e.detail.current)
    })
  },
  item1Tap() {
    this.setData({
      current: 0
    })
  },
  item2Tap() {
    this.setData({
      current: 1
    })
  }
})